import 'package:dio/dio.dart';

class FeishuApi {
  static Future<String?> fetchTenantAccessToken(
      Dio dio, String feishuAppId, String feishuAppSecret) async {
    var data = {'app_id': feishuAppId, 'app_secret': feishuAppSecret};
    return dio
        .post(
            "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal",
            data: data)
        .then((value) {
      return value.data?['tenant_access_token'];
    });
  }

  static Future<dynamic> fetchRecords(
      Dio dio, String accessToken, String appToken, String tableId) async {
    dio.options.headers['Authorization'] = 'Bearer $accessToken';
    return dio
        .get(
            'https://open.feishu.cn/open-apis/bitable/v1/apps/$appToken/tables/$tableId/records')
        .then((value) => value.data);
  }
}
